package com.atguigu.crowd.constant;

import java.util.HashSet;
import java.util.Set;

/**
 * @author zzqstart
 * @Description
 * @date 2022-09-19 13:11
 */
public class AccessPassResources {
    public static final Set<String> PASS_RES_SET = new HashSet<>();

    static {
        PASS_RES_SET.add("/");
        PASS_RES_SET.add("/auth/member/send/short/message.json");
        PASS_RES_SET.add("/auth/member/do/regist");
        PASS_RES_SET.add("/auth/member/do/login");
        PASS_RES_SET.add("/auth/member/do/logout");
        PASS_RES_SET.add("/auth/member/to/reg/page.html");
        PASS_RES_SET.add("/auth/member/to/login/page");
    }

    public static final Set<String> PASS_STATIC_RES_SET = new HashSet<>();

    static {
        PASS_STATIC_RES_SET.add("bootstrap");
        PASS_STATIC_RES_SET.add("css");
        PASS_STATIC_RES_SET.add("fonts");
        PASS_STATIC_RES_SET.add("img");
        PASS_STATIC_RES_SET.add("jquery");
        PASS_STATIC_RES_SET.add("layer");
        PASS_STATIC_RES_SET.add("myscript");
        PASS_STATIC_RES_SET.add("script");
        PASS_STATIC_RES_SET.add("ztree");
    }

    public static boolean judgeCurrentServletWhetherStaticResources(String servletPath){
        // 判断当前servletPath是否有效
        if (servletPath == null || servletPath.length() == 0){
            throw new RuntimeException();
        }
        // 将servletpath以“/”拆分
        String[] split = servletPath.split("/");
        String firstLeverPath = split[1];
        return PASS_STATIC_RES_SET.contains(firstLeverPath);
    }
}
